{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    ""
   ]
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "1、不同的文档，使用不同的文档加载器 （熟悉）\n",
    "\n",
    "txt文档：TextLoader\n",
    "\n",
    "pdf文档：PyPDFLoader\n",
    "\n",
    "csv文档：CSVLoader\n",
    "\n",
    "json文档：JSONLoader\n",
    "\n",
    "html文档：UnstructuredHTMLLoader\n",
    "\n",
    "md文档：UnStructuredMarkdownLoader\n",
    "\n",
    "文件目录：DirectoryLoader\n",
    "\n",
    "\n",
    "2、创建好XxxLoader的实例以后，都需要调用load()，在内存中返回一个list[Document]\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ],
   "id": "f9e66e7ce36e9de"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 1、加载Txt文档",
   "id": "a5959a08aa92fedf"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-01T07:20:06.585816Z",
     "start_time": "2025-10-01T07:20:06.577924Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_community.document_loaders import TextLoader\n",
    "\n",
    "# 指明txt文档的路径\n",
    "file_path = \"./asset/load/01-langchain-utf-8.txt\"\n",
    "\n",
    "# 创建一个TextLoader的实例\n",
    "text_loader = TextLoader(\n",
    "    file_path=file_path,\n",
    "    encoding=\"utf-8\"\n",
    ")\n",
    "\n",
    "# 调用load()，返回一个list[Document]\n",
    "docs = text_loader.load()"
   ],
   "id": "1cf8e3cd4ea512cc",
   "outputs": [],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-01T07:20:09.343486Z",
     "start_time": "2025-10-01T07:20:09.339204Z"
    }
   },
   "cell_type": "code",
   "source": [
    "print(docs)\n",
    "\n",
    "print(len(docs)) # 查看列表中元素的个数‘\n",
    "\n",
    "print(docs[0])"
   ],
   "id": "50068cfed708c5c8",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Document(metadata={'source': './asset/load/01-langchain-utf-8.txt'}, page_content='LangChain 是一个用于构建基于大语言模型（LLM）应用的开发框架，旨在帮助开发者更高效地集成、管理和增强大语言模型的能力，构建端到端的应用程序。它提供了一套模块化工具和接口，支持从简单的文本生成到复杂的多步骤推理任务')]\n",
      "1\n",
      "page_content='LangChain 是一个用于构建基于大语言模型（LLM）应用的开发框架，旨在帮助开发者更高效地集成、管理和增强大语言模型的能力，构建端到端的应用程序。它提供了一套模块化工具和接口，支持从简单的文本生成到复杂的多步骤推理任务' metadata={'source': './asset/load/01-langchain-utf-8.txt'}\n"
     ]
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-01T05:57:35.023882Z",
     "start_time": "2025-10-01T05:57:35.017442Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "# 显示Document对象的元数据\n",
    "print(docs[0].metadata)\n",
    "\n",
    "# 显示文档中的内容信息\n",
    "print(docs[0].page_content)"
   ],
   "id": "ff2ef3d2b6791be4",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'source': './asset/load/01-langchain-utf-8.txt'}\n",
      "LangChain 是一个用于构建基于大语言模型（LLM）应用的开发框架，旨在帮助开发者更高效地集成、管理和增强大语言模型的能力，构建端到端的应用程序。它提供了一套模块化工具和接口，支持从简单的文本生成到复杂的多步骤推理任务\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-01T07:20:12.981373Z",
     "start_time": "2025-10-01T07:20:12.969800Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "from langchain_community.document_loaders import TextLoader\n",
    "\n",
    "# 指明txt文档的路径\n",
    "file_path = \"./asset/load/01-langchain-gbk.txt\"\n",
    "\n",
    "# 创建一个TextLoader的实例\n",
    "text_loader = TextLoader(\n",
    "    file_path=file_path,\n",
    "    encoding=\"gbk\",  #此时使用的解码集一定要与当初存储此文件使用的编码集相同，否则报错！\n",
    ")\n",
    "\n",
    "# 调用load()，返回一个list[Document]\n",
    "docs = text_loader.load()\n",
    "\n",
    "print(docs)"
   ],
   "id": "924f54209456538b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Document(metadata={'source': './asset/load/01-langchain-gbk.txt'}, page_content='LangChain 是一个用于构建基于大语言模型（LLM）应用的开发框架，旨在帮助开发者更高效地集成、管理和增强大语言模型的能力，构建端到端的应用程序。它提供了一套模块化工具和接口，支持从简单的文本生成到复杂的多步骤推理任务')]\n"
     ]
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 2、加载pdf文档",
   "id": "d69305955465a7b4"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-01T05:59:42.493638Z",
     "start_time": "2025-10-01T05:59:42.045202Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "from langchain_community.document_loaders.pdf import PyPDFLoader\n",
    "\n",
    "pdf_loader = PyPDFLoader(\n",
    "    file_path=\"./asset/load/02-load.pdf\"\n",
    ")\n",
    "\n",
    "docs = pdf_loader.load()\n",
    "\n",
    "print(docs)\n",
    "\n",
    "print(len(docs))"
   ],
   "id": "37626095e897ed0c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Document(metadata={'producer': 'Microsoft® Word 2019', 'creator': 'Microsoft® Word 2019', 'creationdate': '2025-06-20T17:18:19+08:00', 'moddate': '2025-06-20T17:18:19+08:00', 'source': './asset/load/02-load.pdf', 'total_pages': 1, 'page': 0, 'page_label': '1'}, page_content='\"他的车，他的命！ 他忽然想起来，一年，二年，至少有三四年；一滴汗，两滴汗，不\\n知道多少万滴汗，才挣出那辆车。从风里雨里的咬牙，从饭里茶里的自苦，才赚出那辆车。\\n那辆车是他的一切挣扎与困苦的总结果与报酬，像身经百战的武士的一颗徽章。……他老想\\n着远远的一辆车，可以使他自由，独立，像自己的手脚的那么一辆车。\" \\n \\n\"他吃，他喝，他嫖，他赌，他懒，他狡猾， 因为他没了心，他的心被人家摘了去。他\\n只剩下那个高大的肉架子，等着溃烂，预备着到乱死岗子去。……体面的、要强的、好梦想\\n的、利己的、个人的、健壮的、伟大的祥子，不知陪着人家送了多少回殡；不知道何时何地\\n会埋起他自己来， 埋起这堕落的、 自私的、 不幸的、 社会病胎里的产儿， 个人主义的末路鬼！\\n\"')]\n",
      "1\n"
     ]
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "也可以加载网络中的一个文件：",
   "id": "1e31e59c31f82728"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-01T06:01:41.526019Z",
     "start_time": "2025-10-01T06:01:40.671017Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_community.document_loaders.pdf import PyPDFLoader\n",
    "\n",
    "pdf_loader = PyPDFLoader(\n",
    "    file_path=\"https://arxiv.org/pdf/2302.03803\"\n",
    ")\n",
    "\n",
    "docs = pdf_loader.load()\n",
    "\n",
    "print(len(docs))\n",
    "\n",
    "print(docs)\n",
    "\n",
    "# for doc in docs:\n",
    "#     print(doc)\n",
    "#     print(\"~\"*20)"
   ],
   "id": "3cb1c2dc2a8102cc",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n",
      "[Document(metadata={'producer': 'dvips + GPL Ghostscript GIT PRERELEASE 9.22', 'creator': 'LaTeX with hyperref', 'creationdate': '2023-02-08T20:27:28-05:00', 'moddate': '2023-02-08T20:27:28-05:00', 'title': '', 'subject': '', 'author': '', 'keywords': '', 'source': 'https://arxiv.org/pdf/2302.03803', 'total_pages': 8, 'page': 0, 'page_label': '1'}, page_content='arXiv:2302.03803v1  [math.AG]  7 Feb 2023\\nA WEAK (k, k )-LEFSCHETZ THEOREM FOR PROJECTIVE\\nTORIC ORBIFOLDS\\nWilliam D. Montoya\\nInstituto de Matem´ atica, Estat´ ıstica e Computa¸ c˜ ao Cient´ ıﬁca,\\nUniversidade Estadual de Campinas (UNICAMP),\\nRua S´ ergio Buarque de Holanda 651, 13083-859, Campinas, SP , Brazil\\nFebruary 9, 2023\\nAbstract\\nFirstly we show a generalization of the (1,1)-Lefschetz theorem for projective\\ntoric orbifolds and secondly we prove that on 2k-dimensional quasi-smooth hyper-\\nsurfaces coming from quasi-smooth intersection surfaces, under the Cayley trick,\\nevery rational (k, k)-cohomology class is algebraic, i.e., the Hodge conjectureholds\\non them.\\n1 Introduction\\nIn [3] we proved that, under suitable conditions, on a very general codimension s quasi-\\nsmooth intersection subvariety X in a projective toric orbifold Pd\\nΣ with d +s = 2(k +1)\\nthe Hodge conjecture holds, that is, every (p, p )-cohomology class, under the Poincar´ e\\nduality is a rational linear combination of fundamental classes of alge braic subvarieties\\nof X. The proof of the above-mentioned result relies, for p ≠ d +1 − s, on a Lefschetz\\nDate: February 9, 2023\\n2020 Mathematics Subject Classiﬁcation: 14C30, 14M10, 14J70, 14M25\\nKeywords: (1,1)- Lefschetz theorem, Hodge conjecture, toric varieties, complete intersection\\nEmail: wmontoya@ime.unicamp.br\\n1'), Document(metadata={'producer': 'dvips + GPL Ghostscript GIT PRERELEASE 9.22', 'creator': 'LaTeX with hyperref', 'creationdate': '2023-02-08T20:27:28-05:00', 'moddate': '2023-02-08T20:27:28-05:00', 'title': '', 'subject': '', 'author': '', 'keywords': '', 'source': 'https://arxiv.org/pdf/2302.03803', 'total_pages': 8, 'page': 1, 'page_label': '2'}, page_content='theorem ([7]) and the Hard Lefschetz theorem for projective orb ifolds ([11]). When p =\\nd +1 −s the proof relies on the Cayley trick, a trick which associates to X a quasi-smooth\\nhypersurface Y in a projective vector bundle, and the Cayley Proposition (4.3) which\\ngives an isomorphism of some primitive cohomologies (4.2) of X and Y . The Cayley\\ntrick, following the philosophy of Mavlyutov in [7], reduces results kn own for quasi-smooth\\nhypersurfaces to quasi-smooth intersection subvarieties. The id ea in this paper goes the\\nother way around, we translate some results for quasi-smooth int ersection subvarieties to\\nquasi-smooth hypersurfaces, mainly the (1, 1)-Lefschetz theorem.\\nAcknowledgement. I thank Prof. Ugo Bruzzo and Tiago Fonseca for useful discus-\\nsions. I also acknowledge support from FAPESP postdoctoral gra nt No. 2019/23499-7.\\n2 Preliminaries and Notation\\n2.1 Toric varieties\\nLet M be a free abelian group of rank d, let N =Hom(M, Z ), and NR =N ⊗Z R.\\nDeﬁnition 2.1. • A convex subset σ ⊂NR is a rational k-dimensional simplicial cone\\nif there exist k linearly independent primitive elements e1, . . . , e k ∈ N such that σ =\\n{µ1e1 +⋯+ µkek}.\\n• The generators ei are integral if for every i and any nonnegative rational number µ\\nthe product µei is in N only if µ is an integer.\\n• Given two rational simplicial cones σ, σ′ one says that σ′ is a face of σ (σ′ < σ) if\\nthe set of integral generators of σ′ is a subset of the set of integral generators of σ.\\n• A ﬁnite set Σ ={σ1, . . . , σ t} of rational simplicial cones is called a rational simplicia l\\ncomplete d-dimensional fan if:\\n1. all faces of cones in Σ are in Σ ;\\n2. if σ, σ ′ ∈Σ then σ ∩σ′ <σ and σ ∩σ′ <σ′;\\n3. NR =σ1 ∪⋅⋅⋅∪ σt.\\nA rational simplicial complete d-dimensional fan Σ deﬁnes a d-dimensional toric variety\\nPd\\nΣ having only orbifold singularities which we assume to be projective. Mo reover, T ∶=\\nN ⊗Z C∗ ≃ (C∗)d is the torus action on Pd\\nΣ . We denote by Σ (i) the i-dimensional cones\\n2'), Document(metadata={'producer': 'dvips + GPL Ghostscript GIT PRERELEASE 9.22', 'creator': 'LaTeX with hyperref', 'creationdate': '2023-02-08T20:27:28-05:00', 'moddate': '2023-02-08T20:27:28-05:00', 'title': '', 'subject': '', 'author': '', 'keywords': '', 'source': 'https://arxiv.org/pdf/2302.03803', 'total_pages': 8, 'page': 2, 'page_label': '3'}, page_content='of Σ and each ρ ∈Σ corresponds to an irreducible T -invariant Weil divisor Dρ on Pd\\nΣ . Let\\nCl(Σ ) be the group of Weil divisors on Pd\\nΣ module rational equivalences.\\nThe total coordinate ring of Pd\\nΣ is the polynomial ring S = C[xρ /divides.alt0 ρ ∈ Σ (1)], S has the\\nCl(Σ )-grading, a Weil divisor D =∑ρ∈Σ (1) uρDρ determines the monomial xu ∶=∏ρ∈Σ (1) xuρ\\nρ ∈\\nS and conversely deg (xu)=[D]∈Cl(Σ ).\\nFor a cone σ ∈ Σ, ˆσ is the set of 1-dimensional cone in Σ that are not contained in σ\\nand xˆσ ∶=∏ρ∈ˆσ xρ is the associated monomial in S.\\nDeﬁnition 2.2. The irrelevant ideal of Pd\\nΣ is the monomial ideal BΣ ∶=< xˆσ /divides.alt0 σ ∈ Σ > and\\nthe zero locus Z(Σ )∶=V(BΣ ) in the aﬃne space Ad ∶=Spec(S) is the irrelevant locus.\\nProposition 2.3 (Theorem 5.1.11 [5]) . The toric variety Pd\\nΣ is a categorical quotient\\nAd ∖Z(Σ ) by the group Hom(Cl(Σ ), C∗) and the group action is induced by the Cl(Σ )-\\ngrading of S.\\n2.2 Orbifolds\\nNow we give a brief introduction to complex orbifolds and we mention th e needed theorems\\nfor the next section. Namely: de Rham theorem and Dolbeault theor em for complex\\norbifolds.\\nDeﬁnition 2.4. A complex orbifold of complex dimension d is a singular complex space\\nwhose singularities are locally isomorphic to quotient sin gularities Cd/slash.left G, for ﬁnite sub-\\ngroups G ⊂Gl(d, C).\\nDeﬁnition 2.5. A diﬀerential form on a complex orbifold Z is deﬁned locally at z ∈Z as\\na G-invariant diﬀerential form on Cd where G ⊂ Gl(d, C) and Z is locally isomorphic to\\nCd/slash.left G around z.\\nRoughly speaking the local geometry of orbifolds reduces to local G-invariant geometry.\\nWe have a complex of diﬀerential forms (A●(Z), d )and a double complex (A●, ●(Z), ∂, ¯∂)\\nof bigraded diﬀerential forms which deﬁne the de Rham and the Dolbe ault cohomology\\ngroups (for a ﬁxed p ∈N) respectively:\\nH●\\ndR(Z, C)∶= kerd\\nim d and Hp, ●(Z, ¯∂)∶= ker ¯∂\\nim ¯∂\\nTheorem 2.6 (Theorem 3.4.4 in [4] and Theorem 1.2 in [1] ) . Let Z be a compact complex\\norbifold. There are natural isomorphisms:\\n3'), Document(metadata={'producer': 'dvips + GPL Ghostscript GIT PRERELEASE 9.22', 'creator': 'LaTeX with hyperref', 'creationdate': '2023-02-08T20:27:28-05:00', 'moddate': '2023-02-08T20:27:28-05:00', 'title': '', 'subject': '', 'author': '', 'keywords': '', 'source': 'https://arxiv.org/pdf/2302.03803', 'total_pages': 8, 'page': 3, 'page_label': '4'}, page_content='• H●\\ndR(Z, C)≃H●(Z, C)\\n• Hp, ●(Z, ¯∂)≃H●(X, Ω p\\nZ )\\n3 (1,1)-Lefschetz theorem for projective toric orbifolds\\nDeﬁnition 3.1. A subvariety X ⊂Pd\\nΣ is quasi-smooth if V(IX )⊂A#Σ (1) is smooth outside\\nZ(Σ ).\\nExample 3.2. Quasi-smooth hypersurfaces or more generally quasi-smooth inte rsection sub-\\nvarieties are quasi-smooth subvarieties (see [2] or [7] for more det ails).\\n△\\nRemark 3.3. Quasi-smooth subvarieties are suborbifolds of Pd\\nΣ in the sense of Satake in [8].\\nIntuitively speaking they are subvarieties whose only singularities co me from the ambient\\nspace.\\n△\\nTheorem 3.4. Let X ⊂ Pd\\nΣ be a quasi-smooth subvariety. Then every (1, 1)-cohomology\\nclass λ ∈H1, 1(X)∩H2(X, Z) is algebraic\\nProof. From the exponential short exact sequence\\n0 →Z →OX →O∗\\nX →0\\nwe have a long exact sequence in cohomology\\nH1(O∗\\nX )→H2(X, Z) →H2(OX )≃H0, 2(X)\\nwhere the last isomorphisms is due to Steenbrink in [9]. Now, it is enoug h to prove the\\ncommutativity of the next diagram\\nH2(X, Z) → → \\n↓ ↓ \\nH2(X, OX )\\n≃ Dolbeault\\n↓ ↓ \\nH2(X, C)\\nde Rham ≃\\n↓ ↓ \\nH2\\ndR(X, C) → → H0, 2\\n¯∂ (X)\\n4'), Document(metadata={'producer': 'dvips + GPL Ghostscript GIT PRERELEASE 9.22', 'creator': 'LaTeX with hyperref', 'creationdate': '2023-02-08T20:27:28-05:00', 'moddate': '2023-02-08T20:27:28-05:00', 'title': '', 'subject': '', 'author': '', 'keywords': '', 'source': 'https://arxiv.org/pdf/2302.03803', 'total_pages': 8, 'page': 4, 'page_label': '5'}, page_content='The key points are the de Rham and Dolbeault’s isomorphisms for orbif olds. The rest\\nof the proof follows as the (1, 1)-Lefschetz theorem in [6].\\nRemark 3.5. For k = 1 and Pd\\nΣ as the projective space, we recover the classical (1, 1)-\\nLefschetz theorem.\\n△\\nBy the Hard Lefschetz Theorem for projective orbifolds (see [11] for details) we get an\\nisomorphism of cohomologies :\\nH●(X, Q) ≃H2 dim X−●(X, Q)\\ngiven by the Lefschetz morphism and since it is a morphism of Hodge st ructures, we have:\\nH1, 1(X, Q) ≃Hdim X−1, dim X−1(X, Q)\\nFor X as before:\\nCorollary 3.6. If the dimension of X is 1, 2 or 3. The Hodge conjecture holds on X.\\nProof. If the dimCX = 1 the result is clear by the Hard Lefschetz theorem for projective\\norbifolds. The dimension 2 and 3 cases are covered by Theorem 3.5 an d the Hard Lefschetz.\\ntheorem.4 Cayley trick and Cayley proposition\\nThe Cayley trick is a way to associate to a quasi-smooth intersection subvariety a quasi-\\nsmooth hypersurface. Let L1, . . . , L s be line bundles on Pd\\nΣ and let π ∶ P(E) → Pd\\nΣ be the\\nprojective space bundle associated to the vector bundle E =L1 ⊕⋯⊕ Ls. It is known that\\nP(E) is a (d +s −1)-dimensional simplicial toric variety whose fan depends on the degre es\\nof the line bundles and the fan Σ. Furthermore, if the Cox ring, witho ut considering the\\ngrading, of Pd\\nΣ is C[x1, . . . , x m] then the Cox ring of P(E) is\\nC[x1, . . . , x m, y 1, . . . , y s]\\nMoreover for X a quasi-smooth intersection subvariety cut oﬀ by f1, . . . , f s with deg(fi)=\\n[Li] we relate the hypersurface Y cut oﬀ by F = y1f1 +⋅⋅⋅+ ysfs which turns out to be\\nquasi-smooth. For more details see Section 2 in [7].\\n5'), Document(metadata={'producer': 'dvips + GPL Ghostscript GIT PRERELEASE 9.22', 'creator': 'LaTeX with hyperref', 'creationdate': '2023-02-08T20:27:28-05:00', 'moddate': '2023-02-08T20:27:28-05:00', 'title': '', 'subject': '', 'author': '', 'keywords': '', 'source': 'https://arxiv.org/pdf/2302.03803', 'total_pages': 8, 'page': 5, 'page_label': '6'}, page_content='We will denote P(E) as Pd+s−1\\nΣ ,X to keep track of its relation with X and Pd\\nΣ .\\nThe following is a key remark.\\nRemark 4.1. There is a morphism ι∶X →Y ⊂Pd+s−1\\nΣ ,X . Moreover every point z ∶=(x, y )∈Y\\nwith y ≠ 0 has a preimage. Hence for any subvariety W = V(IW ) ⊂ X ⊂ Pd\\nΣ there exists\\nW ′ ⊂Y ⊂Pd+s−1\\nΣ ,X such that π(W ′)=W , i.e., W ′ ={z =(x, y ) /divides.alt0 x ∈W }.\\n△\\nFor X ⊂ Pd\\nΣ a quasi-smooth intersection variety the morphism in cohomology indu ced\\nby the inclusion i∗ ∶Hd−s(Pd\\nΣ , C)→Hd−s(X, C) is injective by Proposition 1.4 in [7].\\nDeﬁnition 4.2. The primitive cohomology of Hd−s\\nprim(X)is the quotient Hd−s(X, C)/slash.left i∗(Hd−s(Pd\\nΣ , C))\\nand Hd−s\\nprim(X, Q) with rational coeﬃcients.\\nHd−s(Pd\\nΣ , C) and Hd−s(X, C) have pure Hodge structures, and the morphism i∗ is com-\\npatible with them, so that Hd−s\\nprim(X) gets a pure Hodge structure.\\nThe next Proposition is the Cayley proposition.\\nProposition 4.3. [Proposition 2.3 in [3] ] Let X =X1 ∩⋅⋅⋅∩ Xs be a quasi-smooth intersec-\\ntion subvariety in Pd\\nΣ cut oﬀ by homogeneous polynomials f1 . . . f s. Then for p ≠ d+s−1\\n2 , d+s−3\\n2\\nHp−1,d +s−1−p\\nprim (Y )≃Hp−s,d −p\\nprim (X).\\nCorollary 4.4. If d +s =2(k +1),\\nHk+1−s,k +1−s\\nprim (X)≃Hk,k\\nprim(Y )\\nRemark 4.5. The above isomorphisms are also true with rational coeﬃcients since H●(X, C) =\\nH●(X, Q)⊗Q C. See the beginning of Section 7.1 in [10] for more details.\\n△\\n5 Main result\\nTheorem 5.1. Let Y ={F =y1f1 +⋯+ ykfk =0}⊂P2k+1\\nΣ ,X be the quasi-smooth hypersurface\\nassociated to the quasi-smooth intersection surface X = Xf1 ∩⋅⋅⋅∩ Xfk ⊂ Pk+2\\nΣ . Then on Y\\nthe Hodge conjecture holds.\\nProof. If Hk,k\\nprim(X, Q) = 0 we are done. So let us assume Hk,k\\nprim(X, Q) ≠ 0. By the Cayley\\nproposition Hk,k\\nprim(Y, Q) ≃ H1, 1\\nprim(X, Q) and by the (1, 1)-Lefschetz theorem for projective\\n6'), Document(metadata={'producer': 'dvips + GPL Ghostscript GIT PRERELEASE 9.22', 'creator': 'LaTeX with hyperref', 'creationdate': '2023-02-08T20:27:28-05:00', 'moddate': '2023-02-08T20:27:28-05:00', 'title': '', 'subject': '', 'author': '', 'keywords': '', 'source': 'https://arxiv.org/pdf/2302.03803', 'total_pages': 8, 'page': 6, 'page_label': '7'}, page_content='toric orbifolds there is a non-zero algebraic basis λC1 , . . . , λ Cn with rational coeﬃcients of\\nH1, 1\\nprim(X, Q), that is, there are n ∶=h1, 1\\nprim(X, Q) algebraic curves C1, . . . , C n in X such that\\nunder the Poincar´ e duality the class in homology [Ci] goes to λCi , [Ci] ↦ λCi . Recall\\nthat the Cox ring of Pk+2 is contained in the Cox ring of P2k+1\\nΣ ,X without considering the\\ngrading. Considering the grading we have that if α ∈ Cl(Pk+2\\nΣ ) then (α, 0) ∈ Cl(P2k+1\\nΣ ,X ). So\\nthe polynomials deﬁning Ci ⊂ Pk+2\\nΣ can be interpreted in P2k+1\\nX, Σ but with diﬀerent degree.\\nMoreover, by Remark 4.1 each Ci is contained in Y = {F = y1f1 + ⋯ + ykfk = 0} and\\nfurthermore it has codimension k.\\nClaim: {λCi }n\\ni=1 is a basis of Hk,k\\nprim(Y, Q).\\nIt is enough to prove that λCi is diﬀerent from zero in Hk,k\\nprim(Y, Q) or equivalently that the\\ncohomology classes {λCi }n\\ni=1 do not come from the ambient space. By contradiction, let us\\nassume that there exists a j and C ⊂P2k+1\\nΣ ,X such that λC ∈Hk,k (P2k+1\\nΣ ,X , Q) with i∗(λC )=λCj\\nor in terms of homology there exists a (k +2)-dimensional algebraic subvariety V ⊂ P2k+1\\nΣ ,X\\nsuch that V ∩Y = Cj so they are equal as a homology class of P2k+1\\nΣ ,X ,i.e., [V ∩Y ] = [Cj] .\\nIt is easy to check that π(V )∩X =Cj as a subvariety of Pk+2\\nΣ where π ∶ (x, y )↦x. Hence\\n[π(V )∩X] = [Cj] which is equivalent to say that λCj comes from Pk+2\\nΣ which contradicts\\nthe choice of [Cj].\\nRemark 5.2. Into the proof of the previous theorem, the key fact was that on X the\\nHodge conjecture holds and we translate it to Y by contradiction. So, using an analogous\\nargument we have:\\n△\\nProposition 5.3. Let Y ={F =y1fs+⋯+ysfs =0}⊂P2k+1\\nΣ ,X be the quasi-smooth hypersurface\\nassociated to a quasi-smooth intersection subvariety X = Xf1 ∩ ⋅⋅⋅ ∩ Xfs ⊂ Pd\\nΣ such that\\nd +s =2(k +1). If the Hodge conjecture holds on X then it holds as well on Y .\\nCorollary 5.4. If the dimension of Y is 2s −1, 2s or 2s +1 then the Hodge conjecture\\nholds on Y .\\nProof. By Proposition 5.3 and Corollary 3.6.\\n7'), Document(metadata={'producer': 'dvips + GPL Ghostscript GIT PRERELEASE 9.22', 'creator': 'LaTeX with hyperref', 'creationdate': '2023-02-08T20:27:28-05:00', 'moddate': '2023-02-08T20:27:28-05:00', 'title': '', 'subject': '', 'author': '', 'keywords': '', 'source': 'https://arxiv.org/pdf/2302.03803', 'total_pages': 8, 'page': 7, 'page_label': '8'}, page_content='References\\n[1] Angella, D. Cohomologies of certain orbifolds. Journal of Geometry and Physics\\n71 (2013), 117–126.\\n[2] Batyrev, V. V., and Cox, D. A.On the Hodge structure of projective hypersur-\\nfaces in toric varieties. Duke Mathematical Journal 75, 2 (Aug 199 4).\\n[3] Bruzzo, U., and Montoya, W. On the Hodge conjecture for quasi-smooth in-\\ntersections in toric varieties. S˜ ao Paulo J. Math. Sci. Special Section: Geometry in\\nAlgebra and Algebra in Geometry (2021).\\n[4] Caramello Jr, F. C.Introduction to orbifolds. arXiv:1909.08699v6 (2019).\\n[5] Cox, D., Little, J., and Schenck, H.Toric varieties, vol. 124. American Math-\\nematical Soc., 2011.\\n[6] Griffiths, P., and Harris, J. Principles of Algebraic Geometry. John Wiley &\\nSons, Ltd, 1978.\\n[7] Mavlyutov, A. R. Cohomology of complete intersections in toric varieties. Pub-\\nlished in Paciﬁc J. of Math. 191 No. 1 (1999), 133–144.\\n[8] Satake, I. On a Generalization of the Notion of Manifold. Proceedings of the\\nNational Academy of Sciences of the United States of America 42, 6 (1956), 359–363.\\n[9] Steenbrink, J. H. M.Intersection form for quasi-homogeneous singularities. Com-\\npositio Mathematica 34 , 2 (1977), 211–223.\\n[10] Voisin, C. Hodge Theory and Complex Algebraic Geometry I, vol. 1 of Cambridge\\nStudies in Advanced Mathematics . Cambridge University Press, 2002.\\n[11] W ang, Z. Z., and Zaffran, D.A remark on the Hard Lefschetz theorem for K¨ ahler\\norbifolds. Proceedings of the American Mathematical Society 137 , 08 (Aug 2009).\\n8')]\n"
     ]
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 3、加载CSV文档",
   "id": "e642361cd134b09d"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-01T06:03:31.458483Z",
     "start_time": "2025-10-01T06:03:31.445857Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "from langchain_community.document_loaders import CSVLoader\n",
    "\n",
    "csv_loader = CSVLoader(\n",
    "    file_path=\"./asset/load/03-load.csv\"\n",
    ")\n",
    "\n",
    "docs = csv_loader.load()\n",
    "\n",
    "print(len(docs))\n",
    "\n",
    "\n",
    "print(docs)\n",
    "\n",
    "for doc in docs:\n",
    "    print(doc)"
   ],
   "id": "52ce047dfa330fe3",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "[Document(metadata={'source': './asset/load/03-load.csv', 'row': 0}, page_content='id: 1\\ntitle: Introduction to Python\\ncontent: Python is a popular programming language.\\nauthor: John Doe'), Document(metadata={'source': './asset/load/03-load.csv', 'row': 1}, page_content='id: 2\\ntitle: Data Science Basics\\ncontent: Data science involves statistics and machine learning.\\nauthor: Jane Smith'), Document(metadata={'source': './asset/load/03-load.csv', 'row': 2}, page_content='id: 3\\ntitle: Web Development\\ncontent: HTML, CSS and JavaScript are core web technologies.\\nauthor: Mike Johnson'), Document(metadata={'source': './asset/load/03-load.csv', 'row': 3}, page_content='id: 4\\ntitle: Artificial Intelligence\\ncontent: AI is transforming many industries.\\nauthor: Sarah Williams')]\n",
      "page_content='id: 1\n",
      "title: Introduction to Python\n",
      "content: Python is a popular programming language.\n",
      "author: John Doe' metadata={'source': './asset/load/03-load.csv', 'row': 0}\n",
      "page_content='id: 2\n",
      "title: Data Science Basics\n",
      "content: Data science involves statistics and machine learning.\n",
      "author: Jane Smith' metadata={'source': './asset/load/03-load.csv', 'row': 1}\n",
      "page_content='id: 3\n",
      "title: Web Development\n",
      "content: HTML, CSS and JavaScript are core web technologies.\n",
      "author: Mike Johnson' metadata={'source': './asset/load/03-load.csv', 'row': 2}\n",
      "page_content='id: 4\n",
      "title: Artificial Intelligence\n",
      "content: AI is transforming many industries.\n",
      "author: Sarah Williams' metadata={'source': './asset/load/03-load.csv', 'row': 3}\n"
     ]
    }
   ],
   "execution_count": 12
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-01T06:06:14.699984Z",
     "start_time": "2025-10-01T06:06:14.687881Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "from langchain_community.document_loaders import CSVLoader\n",
    "\n",
    "csv_loader = CSVLoader(\n",
    "    file_path=\"./asset/load/03-load.csv\",\n",
    "    source_column=\"author\"\n",
    ")\n",
    "\n",
    "docs = csv_loader.load()\n",
    "print(len(docs))\n",
    "for doc in docs:\n",
    "    print(doc)"
   ],
   "id": "3fc5eb0434b548a8",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "page_content='id: 1\n",
      "title: Introduction to Python\n",
      "content: Python is a popular programming language.\n",
      "author: John Doe' metadata={'source': 'John Doe', 'row': 0}\n",
      "page_content='id: 2\n",
      "title: Data Science Basics\n",
      "content: Data science involves statistics and machine learning.\n",
      "author: Jane Smith' metadata={'source': 'Jane Smith', 'row': 1}\n",
      "page_content='id: 3\n",
      "title: Web Development\n",
      "content: HTML, CSS and JavaScript are core web technologies.\n",
      "author: Mike Johnson' metadata={'source': 'Mike Johnson', 'row': 2}\n",
      "page_content='id: 4\n",
      "title: Artificial Intelligence\n",
      "content: AI is transforming many industries.\n",
      "author: Sarah Williams' metadata={'source': 'Sarah Williams', 'row': 3}\n"
     ]
    }
   ],
   "execution_count": 14
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "# 4、加载JSON文档\n",
    "\n",
    "举例1：加载json文件中的所有的数据"
   ],
   "id": "af68fcbe3bd9a7ff"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-01T06:10:41.047519Z",
     "start_time": "2025-10-01T06:10:41.037803Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "from langchain_community.document_loaders import JSONLoader\n",
    "\n",
    "json_loader = JSONLoader(\n",
    "    file_path=\"./asset/load/04-load.json\",\n",
    "    jq_schema=\".\", #表示加载所有的字段\n",
    "    text_content=False, #将加载的json对象转换为json字符串\n",
    ")\n",
    "\n",
    "docs = json_loader.load()\n",
    "\n",
    "print(docs)"
   ],
   "id": "3e03e4873b337874",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Document(metadata={'source': '/Users/shishizan/project-python/LangChain-tutorial/chapter07-RAG/asset/load/04-load.json', 'seq_num': 1}, page_content='{\"messages\": [{\"sender\": \"Alice\", \"content\": \"Hello, how are you today?\", \"timestamp\": \"2023-05-15T10:00:00\"}, {\"sender\": \"Bob\", \"content\": \"I\\'m doing well, thanks for asking!\", \"timestamp\": \"2023-05-15T10:02:00\"}, {\"sender\": \"Alice\", \"content\": \"Would you like to meet for lunch?\", \"timestamp\": \"2023-05-15T10:05:00\"}, {\"sender\": \"Bob\", \"content\": \"Sure, that sounds great!\", \"timestamp\": \"2023-05-15T10:07:00\"}], \"conversation_id\": \"conv_12345\", \"participants\": [\"Alice\", \"Bob\"]}')]\n"
     ]
    }
   ],
   "execution_count": 18
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "举例2：加载json文件中messages[]中的所有的content字段",
   "id": "1ba821d7a7381a54"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-01T06:12:01.291521Z",
     "start_time": "2025-10-01T06:12:01.283701Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "from langchain_community.document_loaders import JSONLoader\n",
    "\n",
    "json_loader = JSONLoader(\n",
    "    file_path=\"./asset/load/04-load.json\",\n",
    "    jq_schema=\".messages[].content\", #加载messages[]的所有的content字段\n",
    "    #text_content=False, #将加载的json对象转换为json字符串\n",
    ")\n",
    "\n",
    "docs = json_loader.load()\n",
    "\n",
    "for doc in docs:\n",
    "    print(doc.page_content)"
   ],
   "id": "bed8808007dc09c4",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello, how are you today?\n",
      "I'm doing well, thanks for asking!\n",
      "Would you like to meet for lunch?\n",
      "Sure, that sounds great!\n"
     ]
    }
   ],
   "execution_count": 19
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "举例3：提取04-response.json文件中嵌套在 data.items[].content 的文本",
   "id": "de50b2b5de390111"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-01T06:14:21.574102Z",
     "start_time": "2025-10-01T06:14:21.557383Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "from langchain_community.document_loaders import JSONLoader\n",
    "\n",
    "# 方式1：\n",
    "# json_loader = JSONLoader(\n",
    "#     file_path=\"./asset/load/04-response.json\",\n",
    "#     jq_schema=\".data.items[].content\", #data.items[].content\n",
    "# )\n",
    "\n",
    "# 方式2：\n",
    "json_loader = JSONLoader(\n",
    "    file_path=\"./asset/load/04-response.json\",\n",
    "    jq_schema=\".data.items[]\", #data.items[].content\n",
    "    content_key=\".content\",\n",
    "    is_content_key_jq_parsable=True, #用jq解析content_key\n",
    ")\n",
    "\n",
    "docs = json_loader.load()\n",
    "\n",
    "for doc in docs:\n",
    "    print(doc.page_content)"
   ],
   "id": "b1af697199fd2dfb",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This article explains how to parse API responses...\n",
      "Learn to handle nested structures with...\n",
      "Best practices for preserving metadata...\n"
     ]
    }
   ],
   "execution_count": 24
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "举例4：提取04-response.json文件中嵌套在 data.items[] 里的 title、content 和 其文本",
   "id": "d93de19b706c8b30"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-01T06:17:59.087014Z",
     "start_time": "2025-10-01T06:17:59.070772Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "# 1.导入相关依赖\n",
    "from langchain_community.document_loaders import JSONLoader\n",
    "from pprint import pprint\n",
    "\n",
    "# 2.定义json文件的路径\n",
    "file_path = 'asset/load/04-response.json'\n",
    "\n",
    "# 3.定义JSONLoader对象\n",
    "# 提取嵌套在 data.items[].content 的文本，并保留其他字段作为元数据\n",
    "# loader = JSONLoader(\n",
    "#     file_path=file_path,\n",
    "#     # jq_schema=\".data.items[] | {id, author, text: (.title + '\\n' + .content)}\",\n",
    "#     jq_schema='''.data.items[] | {\n",
    "#     id,\n",
    "#     author,\n",
    "#     created_at,\n",
    "#     title, # 保留title字段\n",
    "#     text: (.title + \"\\n\" + .content)\n",
    "#     }''',\n",
    "#     content_key=\".text\",  # 再从条目中提取 content 字段\n",
    "#     is_content_key_jq_parsable=True  # 用jq解析content_key\n",
    "# )\n",
    "loader = JSONLoader(\n",
    "    file_path=file_path,\n",
    "    # jq_schema=\".data.items[] | {id, author, text: (.title + '\\n' + .content)}\",\n",
    "    jq_schema=\".data.items[]\",\n",
    "    content_key='.title + \"\\\\n\\\\n\" + .content',\n",
    "    is_content_key_jq_parsable=True  # 用jq解析content_key\n",
    ")\n",
    "\n",
    "# loader = JSONLoader(\n",
    "#     file_path=file_path,\n",
    "#     # jq_schema=\".data.items[] | {id, author, text: (.title + '\\n' + .content)}\",\n",
    "#     jq_schema='''\n",
    "#         .data.items[] | {\n",
    "#             metadata: {\n",
    "#                 id,\n",
    "#                 author,\n",
    "#                 created_at\n",
    "#             },\n",
    "#             content: (.title + \"\\n\\n\" + .content)\n",
    "#         }\n",
    "#     ''',  # 构建新结构\n",
    "#      content_key='.title + \"\\\\n\\\\n\" + .content',\n",
    "#     is_content_key_jq_parsable=True  # 用jq解析content_key\n",
    "# )\n",
    "\n",
    "# 4.加载\n",
    "data = loader.load()\n",
    "\n",
    "for doc in data:\n",
    "    print(doc.page_content)"
   ],
   "id": "1e4ae02219dd22bd",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Understanding JSONLoader\n",
      "\n",
      "This article explains how to parse API responses...\n",
      "Advanced jq Schema Patterns\n",
      "\n",
      "Learn to handle nested structures with...\n",
      "LangChain Metadata Handling\n",
      "\n",
      "Best practices for preserving metadata...\n"
     ]
    }
   ],
   "execution_count": 25
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 5、加载HTML文档",
   "id": "4629df0f8fc69292"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-01T08:22:23.368813Z",
     "start_time": "2025-10-01T08:22:23.170424Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "# 1.导入相关的依赖\n",
    "from langchain.document_loaders import UnstructuredHTMLLoader\n",
    "\n",
    "# 2.定义UnstructuredHTMLLoader对象\n",
    "# strategy:\n",
    "#   \"fast\" 解析加载html文件速度是比较快（但可能丢失部分结构或元数据）\n",
    "#   \"hi_res\": (高分辨率解析) 解析精准（速度慢一些）\n",
    "#   \"ocr_only\"  强制使用ocr提取文本，仅仅适用于图像（对HTML无效）\n",
    "\n",
    "# mode ：one of `{'paged', 'elements', 'single'}\n",
    "#    \"elements\"  按语义元素（标题、段落、列表、表格等）拆分成多个独立的小文档\n",
    "\n",
    "html_loader = UnstructuredHTMLLoader(\n",
    "    file_path=\"asset/load/05-load.html\",\n",
    "    mode=\"elements\",\n",
    "    strategy=\"fast\"\n",
    ")\n",
    "\n",
    "# 3.加载\n",
    "docs = html_loader.load()\n",
    "\n",
    "print(len(docs))  # 16\n",
    "\n",
    "# 4.打印\n",
    "for doc in docs:\n",
    "    print(doc)\n"
   ],
   "id": "c46a29a820d0d322",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "16\n",
      "page_content='首发于自然语言处理算法与实践' metadata={'source': 'asset/load/05-load.html', 'last_modified': '2025-09-23T01:37:00', 'languages': ['zho'], 'file_directory': 'asset/load', 'filename': '05-load.html', 'filetype': 'text/html', 'category': 'UncategorizedText', 'element_id': 'b082a3e1f4714ffa5f25741f39d82c17'}\n",
      "page_content='RAG:将检索与生成方式相结合来做生成任务' metadata={'source': 'asset/load/05-load.html', 'category_depth': 0, 'last_modified': '2025-09-23T01:37:00', 'languages': ['kor'], 'file_directory': 'asset/load', 'filename': '05-load.html', 'filetype': 'text/html', 'category': 'Title', 'element_id': '46103fd31eae47ed36481d13185af8a9'}\n",
      "page_content='烛之文' metadata={'source': 'asset/load/05-load.html', 'last_modified': '2025-09-23T01:37:00', 'languages': ['kor'], 'file_directory': 'asset/load', 'filename': '05-load.html', 'filetype': 'text/html', 'parent_id': '46103fd31eae47ed36481d13185af8a9', 'category': 'UncategorizedText', 'element_id': 'e02798c2e2bb964165a9e9356b82a3f6'}\n",
      "page_content='1、前言' metadata={'source': 'asset/load/05-load.html', 'category_depth': 1, 'last_modified': '2025-09-23T01:37:00', 'languages': ['zho'], 'file_directory': 'asset/load', 'filename': '05-load.html', 'filetype': 'text/html', 'parent_id': '46103fd31eae47ed36481d13185af8a9', 'category': 'Title', 'element_id': '683a24e897e3a9b862ead6c7979a58dc'}\n",
      "page_content='在上一篇<kNN-NER：利用knn近邻算法来做命名实体识别>提及到文中提出kNN-NER框架是一种检索式增强的方法（retrieval augmented methods），就去查看有关retrieval augmented的paper，了解其核心思想，觉得检索式增强的方法很适合许多业务场景使用，因其以一种简捷的方式将外部知识融于模型中去。今天就分享一篇来自Facebook AI Research的paper<Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks>，论文提出一种检索式增强生成方法，应用于知识密集型的NLP任务（如问答生成），该篇论文被2020年NeurIPS 会议接收。' metadata={'source': 'asset/load/05-load.html', 'last_modified': '2025-09-23T01:37:00', 'languages': ['nor'], 'file_directory': 'asset/load', 'filename': '05-load.html', 'filetype': 'text/html', 'parent_id': '683a24e897e3a9b862ead6c7979a58dc', 'category': 'NarrativeText', 'element_id': 'd345b4a58c84984eb1acf1105fd9f214'}\n",
      "page_content='文中说到，以BERT之类的大规模预训练模型将很多事实知识信息存入模型中，可以看着是pre-trained parametric类型，尽管以fine-tuned方式在下游任务取得显著的成效，但这类方法仍存在无法精准地获取和操作知识的缺陷。而在上述提及的问题上，传统知识检索的方法能很好的应对，这类方法可以看着是non-parametric memory类型。于是，论文提出检索式增强生成方法（retrieval-augmented generation，RAG），主要思想就是将pre-trained parametric与non-parametric memory结合起来做语言生成任务，将两类模型集成起来提高任务处理效果。' metadata={'source': 'asset/load/05-load.html', 'last_modified': '2025-09-23T01:37:00', 'languages': ['nor'], 'file_directory': 'asset/load', 'filename': '05-load.html', 'filetype': 'text/html', 'parent_id': '683a24e897e3a9b862ead6c7979a58dc', 'category': 'UncategorizedText', 'element_id': '2fe8d146b5803ec72e5173bf15599710'}\n",
      "page_content='2、RAG方法' metadata={'source': 'asset/load/05-load.html', 'category_depth': 1, 'last_modified': '2025-09-23T01:37:00', 'languages': ['zho'], 'file_directory': 'asset/load', 'filename': '05-load.html', 'filetype': 'text/html', 'parent_id': '46103fd31eae47ed36481d13185af8a9', 'category': 'Title', 'element_id': '22ca96c9bf71395b8fbbf0928bd7f292'}\n",
      "page_content='上图为论文提出RAG模型的整体示意图。主要包括两大模块：一个检索器（Retriever， p_\\\\eta(z|x) ） + 一个生成器（Generator， p_\\\\theta(y_i|x,z,y_{1:i-1}) ）。前者包括query encoder和document index，分别负责query的编码和文档的索引；后者是一个seq2seq的生成模型。在检索中，使用的是最大内积搜索的方法（MIPS）来检索top-K相关文档。' metadata={'source': 'asset/load/05-load.html', 'last_modified': '2025-09-23T01:37:00', 'languages': ['cat', 'nor'], 'file_directory': 'asset/load', 'filename': '05-load.html', 'filetype': 'text/html', 'parent_id': '22ca96c9bf71395b8fbbf0928bd7f292', 'category': 'NarrativeText', 'element_id': '6bbc63aaa7b3afb8d2685e9b3de78a4c'}\n",
      "page_content='3、实验' metadata={'source': 'asset/load/05-load.html', 'category_depth': 1, 'last_modified': '2025-09-23T01:37:00', 'languages': ['zho'], 'file_directory': 'asset/load', 'filename': '05-load.html', 'filetype': 'text/html', 'parent_id': '46103fd31eae47ed36481d13185af8a9', 'category': 'Title', 'element_id': '4df308cd6991fb9e3f0592371bae26be'}\n",
      "page_content='论文在四类Knowledge-Intensive 任务上进行实验，具体包括开放问答（Open-domain Question Answering ）、摘要式问答（Abstractive Question Answering） 、开放问题生成（Jeopardy Question Generation）、事实判断（Fact Verification ），并使用维基百科（包含2100万个文档）作为检索库。' metadata={'source': 'asset/load/05-load.html', 'last_modified': '2025-09-23T01:37:00', 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '05-load.html', 'filetype': 'text/html', 'parent_id': '4df308cd6991fb9e3f0592371bae26be', 'category': 'UncategorizedText', 'element_id': 'ed6e043c7fd99ec0824b91725c66e0ba'}\n",
      "page_content='4、结语' metadata={'source': 'asset/load/05-load.html', 'category_depth': 1, 'last_modified': '2025-09-23T01:37:00', 'languages': ['zho'], 'file_directory': 'asset/load', 'filename': '05-load.html', 'filetype': 'text/html', 'parent_id': '46103fd31eae47ed36481d13185af8a9', 'category': 'Title', 'element_id': '95bc5bffaa5cfd41f5242f9f8b330761'}\n",
      "page_content='本次分享基于检索增强方式将外部知识融于生成任务中一个新的框架――RAG。对比T5 和 BART这类擅长处理生成任务的模型来说，RAG更新外部知识是不需要重新预训练，成本低；而对比pipeline方法，RAG利用外部知识并不需要构造负责的特征工程。总的来说，RAG方法可作为外部知识融合框架的一种有效实例。' metadata={'source': 'asset/load/05-load.html', 'last_modified': '2025-09-23T01:37:00', 'languages': ['zho', 'kor'], 'file_directory': 'asset/load', 'filename': '05-load.html', 'filetype': 'text/html', 'parent_id': '95bc5bffaa5cfd41f5242f9f8b330761', 'category': 'UncategorizedText', 'element_id': '232dc4ae399e0a8847bfcdeb2e64e215'}\n",
      "page_content='有兴趣可关注笔者公众号：自然语言处理算法与实践' metadata={'source': 'asset/load/05-load.html', 'last_modified': '2025-09-23T01:37:00', 'languages': ['zho', 'kor'], 'file_directory': 'asset/load', 'filename': '05-load.html', 'filetype': 'text/html', 'parent_id': '95bc5bffaa5cfd41f5242f9f8b330761', 'category': 'UncategorizedText', 'element_id': '41f28a1034fdc4291daf652054c20bd2'}\n",
      "page_content='编辑于 2022-04-06 10:47' metadata={'source': 'asset/load/05-load.html', 'last_modified': '2025-09-23T01:37:00', 'languages': ['zho'], 'file_directory': 'asset/load', 'filename': '05-load.html', 'filetype': 'text/html', 'parent_id': '95bc5bffaa5cfd41f5242f9f8b330761', 'category': 'UncategorizedText', 'element_id': 'f70255f8bf13d39885508fd845c22382'}\n",
      "page_content='深度学习（Deep Learning）' metadata={'source': 'asset/load/05-load.html', 'last_modified': '2025-09-23T01:37:00', 'languages': ['nld', 'eng'], 'file_directory': 'asset/load', 'filename': '05-load.html', 'filetype': 'text/html', 'parent_id': '95bc5bffaa5cfd41f5242f9f8b330761', 'category': 'UncategorizedText', 'element_id': '1818d3e8e3a4ce395732bba3428a111d'}\n",
      "page_content='自然语言处理算法与实践' metadata={'source': 'asset/load/05-load.html', 'category_depth': 2, 'last_modified': '2025-09-23T01:37:00', 'languages': ['kor', 'zho'], 'file_directory': 'asset/load', 'filename': '05-load.html', 'filetype': 'text/html', 'parent_id': '95bc5bffaa5cfd41f5242f9f8b330761', 'category': 'Title', 'element_id': '95058f2148219d97462c5c4bfe175502'}\n"
     ]
    }
   ],
   "execution_count": 9
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 6、加载markdown文档",
   "id": "fcf3e5e8dcd24f9b"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-01T08:23:08.737480Z",
     "start_time": "2025-10-01T08:23:08.689579Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "# 1.导入相关的依赖\n",
    "from langchain.document_loaders import UnstructuredMarkdownLoader\n",
    "from pprint import pprint\n",
    "\n",
    "# 2.定义UnstructuredMarkdownLoader对象\n",
    "md_loader = UnstructuredMarkdownLoader(\n",
    "    file_path=\"asset/load/06-load.md\",\n",
    "    strategy=\"fast\"\n",
    ")\n",
    "\n",
    "# 3.加载\n",
    "docs = md_loader.load()\n",
    "\n",
    "print(len(docs))\n",
    "# 4.打印\n",
    "for doc in docs:\n",
    "    pprint(doc)"
   ],
   "id": "961cd7633f4bf8d3",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "Document(metadata={'source': 'asset/load/06-load.md'}, page_content='自然语言处理技术文档\\n\\n本文档用于测试UnstructuredMarkdownLoader的中文处理能力。\\n\\n第一章：简介\\n\\n自然语言处理(NLP)是人工智能的重要分支，主要技术包括：\\n\\n文本分类\\n\\n命名实体识别\\n\\n机器翻译\\n\\n情感分析\\n\\n问答系统\\n\\n第二章：关键技术\\n\\n2.1 预训练模型\\n\\nBERT：双向Transformer编码器\\n\\nGPT：自回归语言模型\\n\\nT5：文本到文本转换框架\\n\\n2.2 代码示例\\n\\n```python from transformers import pipeline\\n\\n创建文本分类管道\\n\\nclassifier = pipeline(\"text-classification\", model=\"bert-base-chinese\")\\n\\nresult = classifier(\"这家餐厅的服务很棒！\") print(result)')\n"
     ]
    }
   ],
   "execution_count": 10
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-01T08:23:19.783688Z",
     "start_time": "2025-10-01T08:23:19.737369Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "# 1.导入相关的依赖\n",
    "from langchain.document_loaders import UnstructuredMarkdownLoader\n",
    "from pprint import pprint\n",
    "\n",
    "# 2.定义UnstructuredMarkdownLoader对象\n",
    "md_loader = UnstructuredMarkdownLoader(\n",
    "    file_path=\"asset/load/06-load.md\",\n",
    "    strategy=\"fast\",\n",
    "    mode=\"elements\"\n",
    ")\n",
    "\n",
    "# 3.加载\n",
    "docs = md_loader.load()\n",
    "\n",
    "print(len(docs))\n",
    "# 4.打印\n",
    "for doc in docs:\n",
    "    pprint(doc)"
   ],
   "id": "5ff4383d84ce962e",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'category_depth': 0, 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'category': 'Title', 'element_id': '184afae73069130590c7608c471f63f4'}, page_content='自然语言处理技术文档')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'parent_id': '184afae73069130590c7608c471f63f4', 'category': 'UncategorizedText', 'element_id': '18f55c7a014f88171f86dc848b58a83b'}, page_content='本文档用于测试UnstructuredMarkdownLoader的中文处理能力。')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'category_depth': 1, 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'parent_id': '184afae73069130590c7608c471f63f4', 'category': 'Title', 'element_id': '6a6844d806798af924a74eecc9bf3c1f'}, page_content='第一章：简介')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'parent_id': '6a6844d806798af924a74eecc9bf3c1f', 'category': 'UncategorizedText', 'element_id': 'e7b3e94da2b42ec341e42747172c2fb1'}, page_content='自然语言处理(NLP)是人工智能的重要分支，主要技术包括：')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'category_depth': 1, 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'parent_id': '6a6844d806798af924a74eecc9bf3c1f', 'category': 'ListItem', 'element_id': 'eb53d308db7e96fa7bf107143411c209'}, page_content='文本分类')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'category_depth': 1, 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'parent_id': '6a6844d806798af924a74eecc9bf3c1f', 'category': 'ListItem', 'element_id': 'd3cd19f3de6c7be342b6d45249ed5936'}, page_content='命名实体识别')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'category_depth': 1, 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'parent_id': '6a6844d806798af924a74eecc9bf3c1f', 'category': 'ListItem', 'element_id': '4af0dd9da13771840a9696cdcbb502e1'}, page_content='机器翻译')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'category_depth': 1, 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'parent_id': '6a6844d806798af924a74eecc9bf3c1f', 'category': 'ListItem', 'element_id': '862050b1daeb945947f4c00587f16954'}, page_content='情感分析')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'category_depth': 1, 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'parent_id': '6a6844d806798af924a74eecc9bf3c1f', 'category': 'ListItem', 'element_id': '7f221beeb60cc8089f9878c70230b9a5'}, page_content='问答系统')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'category_depth': 1, 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'parent_id': '184afae73069130590c7608c471f63f4', 'category': 'Title', 'element_id': 'c2bf8c7c4e88556b7afb7b5407d4fbf2'}, page_content='第二章：关键技术')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'category_depth': 2, 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'parent_id': 'c2bf8c7c4e88556b7afb7b5407d4fbf2', 'category': 'Title', 'element_id': 'd32a685b6777cb3277c7732ca2603203'}, page_content='2.1 预训练模型')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'category_depth': 1, 'emphasized_text_contents': ['BERT'], 'emphasized_text_tags': ['b'], 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'parent_id': 'd32a685b6777cb3277c7732ca2603203', 'category': 'ListItem', 'element_id': '3efd83a33d46349a06c9489309f23af0'}, page_content='BERT：双向Transformer编码器')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'category_depth': 1, 'emphasized_text_contents': ['GPT'], 'emphasized_text_tags': ['b'], 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'parent_id': 'd32a685b6777cb3277c7732ca2603203', 'category': 'ListItem', 'element_id': '042b24863d1db56d10e6222413089a30'}, page_content='GPT：自回归语言模型')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'category_depth': 1, 'emphasized_text_contents': ['T5'], 'emphasized_text_tags': ['b'], 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'parent_id': 'd32a685b6777cb3277c7732ca2603203', 'category': 'ListItem', 'element_id': '7da9d82f5274c3edb7ae917995c08db2'}, page_content='T5：文本到文本转换框架')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'category_depth': 2, 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'parent_id': 'c2bf8c7c4e88556b7afb7b5407d4fbf2', 'category': 'Title', 'element_id': '58fa664fefbefa6e86ee4fc8dd128878'}, page_content='2.2 代码示例')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'parent_id': '58fa664fefbefa6e86ee4fc8dd128878', 'category': 'NarrativeText', 'element_id': '2d72807f991457ffe38dad8b46480b0b'}, page_content='```python from transformers import pipeline')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'category_depth': 0, 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'category': 'Title', 'element_id': 'f5a25376ceb9e9392b4e0b2b60153cca'}, page_content='创建文本分类管道')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'parent_id': 'f5a25376ceb9e9392b4e0b2b60153cca', 'category': 'UncategorizedText', 'element_id': '9745c5d59a60933121ca91a9b71e6acf'}, page_content='classifier = pipeline(\"text-classification\", model=\"bert-base-chinese\")')\n",
      "Document(metadata={'source': 'asset/load/06-load.md', 'languages': ['eng'], 'file_directory': 'asset/load', 'filename': '06-load.md', 'filetype': 'text/markdown', 'last_modified': '2025-09-23T01:37:00', 'parent_id': 'f5a25376ceb9e9392b4e0b2b60153cca', 'category': 'UncategorizedText', 'element_id': '7ebd846af465424c8c01cb58cfa79c86'}, page_content='result = classifier(\"这家餐厅的服务很棒！\") print(result)')\n"
     ]
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 7、加载指定的文件目录",
   "id": "9f7a800958e8a960"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-01T08:23:36.762232Z",
     "start_time": "2025-10-01T08:23:36.746613Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "# 1.导入相关的依赖\n",
    "from langchain.document_loaders import DirectoryLoader\n",
    "from langchain.document_loaders import PythonLoader\n",
    "from pprint import pprint\n",
    "\n",
    "# 2.定义DirectoryLoader对象,指定要加载的文件夹路径、要加载的文件类型和是否使用多线程\n",
    "directory_loader = DirectoryLoader(\n",
    "    path=\"./asset/load\",\n",
    "    glob=\"*.py\",\n",
    "    use_multithreading=True,\n",
    "    show_progress=True,\n",
    "    loader_cls=PythonLoader\n",
    ")\n",
    "\n",
    "# 3.加载\n",
    "docs = directory_loader.load()\n",
    "\n",
    "# 4.打印\n",
    "print(len(docs))\n",
    "for doc in docs:\n",
    "    pprint(doc)"
   ],
   "id": "ac96f867143da337",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 4/4 [00:00<00:00, 1023.31it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "Document(metadata={'source': 'asset/load/07-param_form.py'}, page_content='\"\"\"\\n三 函数参数形式\\n\"\"\"\\n# 1.位置参数\\n# 2.关键字参数\\n# 3.默认参数\\n# 4.不定长参数\\n# 4.1 带一个*\\ndef printInfo(num,*vartuple):\\n    print(num)\\n    print(vartuple)\\n\\nprintInfo(70,60,50)\\n\\nprint(\"-\" * 20)\\n# 如果不定长的参数后面还有参数,必须通过关键字参数传参\\ndef printInfo1(num1,*vartuple,num) :\\n    print(num)\\n    print(num1)\\n    print(vartuple)\\n\\nprintInfo1(10,20,num = 40)\\n\\nprint(\"-\" * 20)\\n# 如果没有给不定长的参数传参,那么得到的是空元组\\nprintInfo1(70,num = 60)\\n# 4.2 带二个*\\ndef printInfo(num,**vardict):\\n    print(num)\\n    print(vardict)\\n    # return\\n\\nprintInfo(10,key1 = 20,key2 = 30)')\n",
      "Document(metadata={'source': 'asset/load/07-fun.py'}, page_content='\"\"\"\\n一 函数入门\\n\"\"\"\\n# 1.不使用函数\\n# 打印欢迎信息1\\nprint(\"********************************\")\\nprint(\"*                              *\")\\nprint(\"*     欢迎来到Python世界       *\")\\nprint(\"*                              *\")\\nprint(\"********************************\")\\n\\n# 打印欢迎信息2\\nprint(\"********************************\")\\nprint(\"*                              *\")\\nprint(\"*     欢迎来到Python世界       *\")\\nprint(\"*                              *\")\\nprint(\"********************************\")\\n\\n# 打印欢迎信息3\\nprint(\"********************************\")\\nprint(\"*                              *\")\\nprint(\"*     欢迎来到Python世界       *\")\\nprint(\"*                              *\")\\nprint(\"********************************\")\\n\\n# 2.使用函数\\ndef print_welcome():\\n    \"\"\"打印欢迎信息\"\"\"\\n    print(\"********************************\")\\n    print(\"*                              *\")\\n    print(\"*     欢迎来到Python世界       *\")\\n    print(\"*                              *\")\\n    print(\"********************************\")\\n\\n# 多次调用函数打印欢迎信息\\nprint_welcome()\\nprint_welcome()\\nprint_welcome()')\n",
      "Document(metadata={'source': 'asset/load/07-fun_retun.py'}, page_content='\"\"\"\\n四 函数的返回值\\n\"\"\"\\n# 1.返回表达式\\n# 2.不带表达式的 return 语句，返回 None。\\n# 3.函数中如果没有 return 语句，在函数运行结束后也会返回 None。\\n# 4.用变量接收返回结果\\n# 5.return 语句可以返回多个值，多个值会放在一个元组中。\\n\\ndef f(a, b, c):\\n    return a, b, c, [a, b, c]\\nprint(f(1, 2, 3))  # (1, 2, 3, [1, 2, 3])\\n')\n",
      "Document(metadata={'source': 'asset/load/07-fun_param.py'}, page_content='\"\"\"\\n二 函数参数\\n\"\"\"\\n\\n\\n# 1. 无参数版本 - 只能计算固定的购物车\\ndef calculate_total_no_params():\\n    \"\"\"计算固定购物车总价\"\"\"\\n    prices = [100, 50, 30]  # 商品价格固定写死在函数内\\n    total = 0\\n    for price in prices:\\n        total += price\\n    return total\\n\\n# 只能计算一个固定的购物车\\nprint(f\"购物车总价:{calculate_total_no_params()}\")\\n\\n# 2.有参数版本 - 可以计算任意购物车\\ndef calculate_total(prices):\\n    \"\"\"计算任意购物车总价\"\"\"\\n    total = 0\\n    for price in prices:\\n        total += price\\n    return total\\n\\n# 可以计算任意购物车\\ncart1 = [100, 50, 30]\\ncart2 = [200, 80, 45, 60]\\ncart3 = [75, 90, 120]\\n\\nprint(\"第一个购物车总价:{calculate_total(cart1)}:\")\\nprint(\"第二个购物车总价:{calculate_total(cart2)}\")\\nprint(f\"第三个购物车总价:{calculate_total(cart3)}\")\\n\\n\\n# 3.参数传递\\n# 3.1 不可变类型 函数传递不可变对象\\n\\ndef changeInt(a) :\\n    print(\"函数体中未改变前a的内存地址\",id(a))\\n    a = 10   #底层会创建一个新对象 然后给新对象一个新值\\n    print(\"函数体中改变后a的内存地址\",id(a))\\n\\na = 2 # 创建一个对象 然后给这个对象一个值\\nchangeInt(a)\\nprint(a)\\nprint(\"函数外b的内存地址\",id(a))\\n\\n\\n\\n# 输出结果\\n# 函数体中未改变前a的内存地址 140729722661336\\n# 函数体中改变后a的内存地址 140729722661592\\n# 2\\n# 函数外b的内存地址 140729722661336\\n\\n\\n# 3.2 可变类型 函数传递不可变对象\\n\\ndef changeList(myList) :\\n    myList[1] = 50\\n    print(\"函数内的值\",myList) # [1,50,3]\\n    print(\"函数内列表的内存\",id(myList)) # 0111111\\n\\nmlist = [1,2,3]  # 底层创建一个对象 地址0111111\\nchangeList(mlist)\\nprint(\"函数外的值\",mlist) # # [1,50,3]\\nprint(\"函数外列表的内存\",id(mlist))\\n\\n# 输出结果\\n# 函数内的值 [1, 50, 3]\\n# 函数内列表的内存 1380193079680\\n# 函数外的值 [1, 50, 3]\\n# 函数外列表的内存 1380193079680\\n\\n')\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "execution_count": 13
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
